--
-- Author: shunguo.chen
-- Date: 2019-05-18 13:20:34
--
-- LegendFashion   传奇武器时装
--

local Clothes = require("app.public.dao.Clothes")

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

local AVATAR_CLASS_ROTATIONS = {-60, 30, 30, -30, 30, 30}

function ClassRef:ctor(data)
    if data then
        self:init(data)
    end
end

-- conf = lengendfashion 配置表
function ClassRef:init(conf)
    self._conf = conf

    self.id = tonumber(conf.ID)
    self.legendId = tonumber(conf.legendID)
    self.lv = tonumber(conf.fashionNum)

    self.limitLv = tonumber(conf.limitLV or 0)

    self._isActive = false
    self._isWear = false

    self._icon = nil
    self._bigIcon = nil
    self._midIcon = nil
end

function ClassRef:getId()
    return self.id
end

-- 激活
function ClassRef:setActive(b)
    self._isActive = b
end
function ClassRef:isActive()
    return self._isActive
end

function ClassRef:getIcon()
    if not self._icon then
        self._icon = table.concat({"art/legend/", self._conf.picIcon, ".png"})
    end
    return self._icon
end
function ClassRef:getBigIcon()
    if not self._bigIcon then
        self._bigIcon = table.concat({"art/legend/", self._conf.picBig, ".png"})
    end
    return self._bigIcon
end
function ClassRef:getMidIcon()
    if not self._midIcon then
        self._midIcon = table.concat({"art/legend/", self._conf.picList, ".png"})
    end
    return self._midIcon
end

-- 获得星图限制
function ClassRef:getLimitMapStar()
    if nil == self.limitMapLv then
        self.limitMapLv = 0
        self.limitMapPg = 0
        local limitMap = self._conf.limitMap
        if limitMap then
            local ary = table.tonumber(string.split(limitMap, "|"))
            self.limitMapLv = ary[1]
            self.limitMapPg = ary[2]/100
        end
    end
    return self.limitMapLv, self.limitMapPg
end

function ClassRef:getFashion()
    if not self._fashion then
        self._fashion = Clothes.new()
        self._fashion:read({tid=tonumber(self._conf.fashionID)})
    end
    return self._fashion
end

function ClassRef:getAvatarParam()
    if not self._avatarParam then
        local fashion = self:getFashion()
        local class = tonumber(fashion:getClass())
        local conf = fashion.confRes

        self._avatarParam = {
            path = conf.folder1,
            armatureName = conf.armature1,
            rotation = AVATAR_CLASS_ROTATIONS[class] or 0,
            rotationEx = -60,
            scale = 1.3
        }
    end
    return self._avatarParam
end

function ClassRef:getCostItems()
    if not self._costItems then
        self._costItems = UD:parseItemsFromString(self._conf.cost)
    end
    return self._costItems
end

return ClassRef